

import {
    getHomeGoods,
    addFootprint,
    getFootprintList,
    getCollectList,
    login,
    userBalance,
} from "../api/api";

export default {
    namespaced: true,
    actions: {

        // 获取商品列表
        getHomeGoods(content, object = { by: '', pageNumber: 1 }) {

            getHomeGoods(object.by, object.pageNumber)

                .then(({ data } = res) => {


                    content.state.HomeGoodsList = data

                }).catch(err => {
                    console.log(err);
                })



            // this._actions['MobilePhone/getdispatch'][0](213)
        },


        // 添加用户足迹
        addFootprint(content, adds) {
            addFootprint(adds)
                .then(({ data } = res) => {

                }).catch(err => {
                    console.log(err);
                })
        },

        // 获取用户足迹
        getFootprintList(content) {

            getFootprintList()
                .then(({ data } = res) => {

                    data.forEach(foo => {
                        foo['checked'] = false
                    });
                    content.state.FootprintList = data
                }).catch(err => {
                    console.log(err);
                })

        },


        // 获取收藏商品
        getCollectList(content) {


            getCollectList()
                .then(({ data } = res) => {

                    data.forEach(foo => {
                        foo['checked'] = false

                    });

                    content.state.CollectList = data

                }).catch(err => {
                    console.log(err);
                })


        },

        // 登录
        login(content, values) {

            login(values['用户名'], values['密码'])
                .then(({ data } = res) => {
                    if (data.userId) {
                        content.state.UserList = data
                        content.state.UserId = data.userId
                        content.state.UserRoot = data.userName
                        // 查询余额
                        this._actions['MobilePhone/userBalance'][0](data.userId)

                        values._this.$router.push({
                            name: 'PersonNal',
                        })

                    }
                }).catch(err => {
                    console.log(err);
                })
        },

        // 查询余额
        userBalance(content, userId) {
            userBalance(userId)
                .then(({ data } = res) => {
                    content.state.ThBalanceList = data
                    content.state.usertatol = data//余款
                    content.state.Recharge = 0//累计充值
                    content.state.Consumption = 0//累计消费


                }).catch(err => {
                    console.log(err);
                })



        },
        getdispatch(con, id) {
            console.log('接到了', id);
        }
    },
    mutations: {

    },
    state: {
        HomeGoodsList: [],//商品列表
        FootprintList: [],//足迹列表
        CollectList: [],// 收藏列表
        UserList: [],//用户列表
        UserId: 0,//用户Id
        UserRoot: '',//用户名字
        ThBalanceList: [],// 余额列表
        usertatol: 0,//余额
        Recharge: 0,//累计充值数目
        Consumption: 0,//累计消费


    },
    getters: {


    }
}